package com.ruoyi.web.controller.djb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.djb.domain.DjbRegHis;
import com.ruoyi.djb.service.IDjbRegHisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登记历史Controller
 * 
 * @author xxd
 * @date 2024-05-21
 */
@Controller
@RequestMapping("/djb/retHist")
public class DjbRegHisController extends BaseController
{
    private String prefix = "djb/retHist";

    @Autowired
    private IDjbRegHisService djbRegHisService;

    @RequiresPermissions("djb:retHist:view")
    @GetMapping()
    public String retHist()
    {
        return prefix + "/retHist";
    }

    /**
     * 查询登记历史列表
     */
    @RequiresPermissions("djb:retHist:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbRegHis djbRegHis)
    {
        startPage();
        List<DjbRegHis> list = djbRegHisService.selectDjbRegHisList(djbRegHis);
        return getDataTable(list);
    }

    /**
     * 导出登记历史列表
     */
    @RequiresPermissions("djb:retHist:export")
    @Log(title = "登记历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbRegHis djbRegHis)
    {
        List<DjbRegHis> list = djbRegHisService.selectDjbRegHisList(djbRegHis);
        ExcelUtil<DjbRegHis> util = new ExcelUtil<DjbRegHis>(DjbRegHis.class);
        return util.exportExcel(list, "登记历史数据");
    }

    /**
     * 新增登记历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存登记历史
     */
    @RequiresPermissions("djb:retHist:add")
    @Log(title = "登记历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbRegHis djbRegHis)
    {
        return toAjax(djbRegHisService.insertDjbRegHis(djbRegHis));
    }

    /**
     * 修改登记历史
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbRegHis djbRegHis = djbRegHisService.selectDjbRegHisById(id);
        mmap.put("djbRegHis", djbRegHis);
        return prefix + "/edit";
    }

    /**
     * 修改保存登记历史
     */
    @RequiresPermissions("djb:retHist:edit")
    @Log(title = "登记历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbRegHis djbRegHis)
    {
        return toAjax(djbRegHisService.updateDjbRegHis(djbRegHis));
    }

    /**
     * 删除登记历史
     */
    @RequiresPermissions("djb:retHist:remove")
    @Log(title = "登记历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbRegHisService.deleteDjbRegHisByIds(ids));
    }
}
